﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Services.Description;
using Gx.Bll.Manage;
using Gx.Bll.OtherBll;
using Gx.Model;
using Gx.Model.Entity;
using Gx.Model.Enums;
using Gx.Model.Other;
using Gx.Model.ViewModel;
using Newtonsoft.Json;

namespace Gx.ColdWarehouseErp.Controllers
{
    /// <summary>
    /// 基础数据管理
    /// </summary>
    public class BasicManageController : BaseController
    {
        private readonly E_DepartmentInfoBll depBll = new E_DepartmentInfoBll();
        private readonly M_DictInfoBll dictBll = new M_DictInfoBll();
        private readonly E_LevelInfoBll levelBll = new E_LevelInfoBll();
        private readonly TreeViewBll tvBll = new TreeViewBll();

        protected readonly LKGoodsSpecBll lKGoodsSpecBll = new LKGoodsSpecBll();
        protected readonly LKGoodsTypesBll lKGoodsTypesBll = new LKGoodsTypesBll();
        protected readonly LKCostTypesBll lKCostTypesBll = new LKCostTypesBll();
        protected readonly LKWareHouseBll lKWareHouseBll = new LKWareHouseBll();
        private readonly LKGoodsBll lKGoodsBll = new LKGoodsBll();
        private readonly C_AreaInfoBll areaBll = new C_AreaInfoBll();
        protected readonly LKBillTemplateBll lKBillTemplateBll = new LKBillTemplateBll();
        protected LKCompanyBll lKCompanyBll = new LKCompanyBll();
        protected LKCustomerLevelBll customerlevelBll = new LKCustomerLevelBll();
        #region 部门信息

        [HttpGet]
        public ActionResult DepList()
        {
            return View();
        }

        [HttpPost]
        public ActionResult InitDepTree()
        {
            List<TreeView> DeptList = depBll.GetDepJson();
            return Json(DeptList);
        }

        [HttpPost]
        public ActionResult AddDep(E_DepartmentInfo model)
        {
            ReturnModel r = depBll.AddDepartmentInfo(model);
            return Json(r);
        }

        [HttpPost]
        public ActionResult EditDep(E_DepartmentInfo model)
        {
            ReturnModel r = depBll.EditDepartmentInfo(model);
            return Json(r);
        }

        [HttpPost]
        public ActionResult DelDep(int id)
        {
            ReturnModel r = depBll.DelDepartmentInfo(id);
            return Json(r);
        }

        /// <summary>
        /// 获取部门对象
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetDepModel(int id)
        {
            E_DepartmentInfo r = depBll.GetDepModel(id);
            return Json(r);

        }

        /// <summary>
        /// 获取部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetDepList()
        {
            List<E_DepartmentInfo> list = depBll.GetDepList();
            return Json(list);
        }

        #endregion

        #region 岗位信息


        public ActionResult LevelList()
        {
            return View();
        }

        /// <summary>
        /// 得到部门下的所有岗位
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult InitDepLevelTree()
        {
            return Json(tvBll.GetDepLevelJson());
        }

        /// <summary>
        /// 编辑岗位信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="levelName"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetDepLevelModel(int levelId)
        {
            return Json(levelBll.GetLevelInfoModel(levelId), JsonRequestBehavior.DenyGet);
        }

        [HttpPost]
        public ActionResult AddLevel(E_LevelInfo model)
        {
            ReturnModel r = levelBll.AddLevelInfo(model);
            return Json(r);
        }


        [HttpPost]
        public ActionResult EditLevel(E_LevelInfo model)
        {
            ReturnModel r = levelBll.EditLevelInfo(model);
            return Json(r);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="levelId"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelLevel(int levelId)
        {
            ReturnModel r = levelBll.DelLevelInfo(levelId);
            return Json(r);
        }

        #endregion

        #region 字典信息

        public ActionResult DictList()
        {
            return View();
        }

        /// <summary>
        /// 获取配置字典的数据快
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult InitDictInfoListCombobox()
        {
            List<M_DictInfo> dictList = new M_DictInfoBll().GetDictListTotal();
            return Json(dictList);
        }
        /// <summary>
        /// 获取配置信息数据列表
        /// </summary>
        /// <param name="dictValue"></param>
        /// <returns></returns>
        public JsonResult GetDictInfoList(int page, int rows, int? dictValue, string dictName)
        {
            List<M_DictInfo> list = new M_DictInfoBll().GetM_DictInfoList(page, rows, dictValue, out int totalCount);
            return Json(new { total = totalCount, rows = list });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddDictInfo(M_DictInfo model)
        {
            ReturnModel r = dictBll.AddDictInfo(model);
            return Json(r);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult EditDictInfo(M_DictInfo model)
        {
            ReturnModel r = dictBll.EditDictInfo(model);
            return Json(r);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult DelDictInfo(int id)
        {
            ReturnModel r = dictBll.DelDictInfo(id);
            return Json(r);
        }

        /// <summary>
        /// 根据枚举类型返回json格式数据
        /// </summary>
        /// <param name="enmuName"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult InitDictCombobox(int dictType)
        {
            List<M_DictInfo> dList = new M_DictInfoBll().GetDictInfoList(dictType);
            return Json(dList);
        }
        #endregion

        #region 商品规格


        public ActionResult LKGoodsSpecList()
        {
            return View();
        }


        /// <summary>
        /// 获取商品规格
        /// </summary>
        /// <returns></returns>
        public JsonResult GetLKGoodsSpec()
        {
            var result = lKGoodsSpecBll.GetLKGoodsSpecs();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 新增商品规格
        /// </summary>
        /// <param name="goodsSpec"></param>
        /// <returns></returns>
        public JsonResult AddLKGoodsSpec(LKGoodsSpec goodsSpec)
        {
            var result = lKGoodsSpecBll.AddLKGoodsSpec(goodsSpec);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        /// <summary>
        /// 编辑商品规格
        /// </summary>
        /// <param name="goodsSpec"></param>
        /// <returns></returns>
        public JsonResult EditLKGoodsSpec(LKGoodsSpec goodsSpec)
        {
            var result = lKGoodsSpecBll.EditLKGoodsSpec(goodsSpec);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除商品规格
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteLKGoodsSpec(int id)
        {
            var result = lKGoodsSpecBll.DeleteLKGoodsSpec(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }
        #endregion

        #region 商品类别

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult LKGoodsTypesList()
        {
            return View();
        }


        /// <summary>
        /// 获取商品类别
        /// </summary>
        /// <returns></returns>
        public JsonResult GetLKGoodsTypes()
        {
            var result = lKGoodsTypesBll.GetLKGoodsTypes();
            return Json(result);
        }
        /// <summary>
        /// 获取商品类别comboxtree
        /// </summary>
        /// <returns></returns>
        public JsonResult GetTypeComboxTree()
        {
            var result = lKGoodsTypesBll.GetTypeComboxTree();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 新增商品类别
        /// </summary>
        /// <param name="goodsTypes"></param>
        /// <returns></returns>
        public JsonResult AddLKGoodsTypes(LKGoodsTypes goodsTypes)
        {
            var result = lKGoodsTypesBll.AddLKGoodsTypes(goodsTypes);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        /// <summary>
        /// 编辑商品类别
        /// </summary>
        /// <param name="goodsTypes"></param>
        /// <returns></returns>
        public JsonResult EditLKGoodsTypes(LKGoodsTypes goodsTypes)
        {
            var result = lKGoodsTypesBll.EditLKGoodsTypes(goodsTypes);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除商品类别
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteLKGoodsTypes(int id)
        {
            var result = lKGoodsTypesBll.DeleteLKGoodsTypes(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }

        #endregion

        #region 商品基础表


        public ActionResult LKGoodsList()
        {
            return View();
        }

        //商品列表
        public JsonResult GetLKGoodsPageList(GoodsInput input)
        {
            var result = lKGoodsBll.GetLKGoodsPageList(input);
            return JsonList(result.Total, result.List.ToArray());
        }

        /// <summary>
        /// 获取商品
        /// </summary>
        /// <returns></returns>
        public JsonResult GetLKGoods()
        {
            var result = lKGoodsBll.GetLKGoodss();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 新增商品
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        public JsonResult AddLKGoods(LKGoods goods)
        {
            var result = lKGoodsBll.AddLKGoods(goods);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        /// <summary>
        /// 编辑商品
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        public JsonResult EditLKGoods(LKGoods goods)
        {
            var result = lKGoodsBll.EditLKGoods(goods);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteLKGoods(int id)
        {
            var result = lKGoodsBll.DeleteLKGoods(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }
        #endregion

        #region 费用类别


        public ActionResult LKCostTypesList()
        {
            return View();
        }


        /// <summary>
        /// 获取费用类别
        /// </summary>
        /// <returns></returns>
        public JsonResult GetLKCostTypes()
        {
            var result = lKCostTypesBll.GetLKCostTypess();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 新增费用类别
        /// </summary>
        /// <param name="lKCostTypes"></param>
        /// <returns></returns>
        public JsonResult AddLKCostTypes(LKCostTypes lKCostTypes)
        {
            var result = lKCostTypesBll.AddLKCostTypes(lKCostTypes);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        /// <summary>
        /// 编辑费用类别
        /// </summary>
        /// <param name="lKCostTypes"></param>
        /// <returns></returns>
        public JsonResult EditLKCostTypes(LKCostTypes lKCostTypes)
        {
            var result = lKCostTypesBll.EditLKCostTypes(lKCostTypes);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除费用类别
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteLKCostTypes(int id)
        {
            var result = lKCostTypesBll.DeleteLKCostTypes(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }

        #endregion

        #region 仓库管理


        // GET: /LKWareHouse/

        public ActionResult LKWareHousetList()
        {
            return View();
        }


        /// <summary>
        /// 获取一级仓库
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetLKWareHousesTopList()
        {
            List<LKWareHouse> r = lKWareHouseBll.GetLKWareHousesTopList();
            return Json(r);
        }

        /// <summary>
        /// 获取仓库
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetLKWareHouse(int? id)
        {
            var result = lKWareHouseBll.GetLKWareHouses(id);
            return Json(result);
        }

        /// <summary>
        /// 获取所有仓库comboxtree
        /// </summary>
        /// <returns></returns>
        public JsonResult GetAllHouseComboxTree()
        {
            var result = lKWareHouseBll.GetHouseComboxTree();
            return Json(result);
        }

        /// <summary>
        /// 获取当前公司的仓库
        /// </summary>
        /// <returns></returns>
        public JsonResult GetHouseComboxTree()
        {
            var result = lKWareHouseBll.GetHouseComboxTreeByCompany();
            return Json(result);
        }

        /// <summary>
        /// 新增仓库
        /// </summary>
        /// <param name="house"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddLKWareHouse(LKWareHouse house)
        {
            var result = lKWareHouseBll.AddLKWareHouse(house);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        /// <summary>
        /// 编辑仓库
        /// </summary>
        /// <param name="house"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult EditLKWareHouse(LKWareHouse house)
        {
            var result = lKWareHouseBll.EditLKWareHouse(house);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除仓库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult DeleteLKWareHouse(int id)
        {
            var result = lKWareHouseBll.DeleteLKWareHouse(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }
        #endregion

        #region 城市管理


        public ActionResult AreaList()
        {
            return View();
        }

        public JsonResult GetAreaInfoList(int? id)
        {
            List<C_AreaInfo> list = areaBll.GetAreaInfoList(id);
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult AddAreaInfo(C_AreaInfo model)
        {
            ReturnModel<C_AreaInfo> r = areaBll.AddC_AreaInfo(model);
            return Json(r);
        }

        [HttpPost]
        public ActionResult EditAreaInfo(C_AreaInfo model)
        {
            ReturnModel<C_AreaInfo> r = areaBll.EditC_AreaInfo(model);
            return Json(r);
        }

        [HttpPost]
        public ActionResult DelAreaInfo(int id)
        {
            ReturnModel<C_AreaInfo> r = areaBll.DelC_AreaInfo(id);
            return Json(r);
        }

        /// 获取省市区
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public JsonResult InitArea(int parentId)
        {
            return Json(new C_AreaInfoBll().GetAreaInfoList(parentId));
        }

        [HttpPost]
        public JsonResult GetAreaInfoModel(int areaId)
        {
            ReturnModel<C_AreaInfo> r = areaBll.GetAreaInfoModel(areaId);
            return Json(r);
        }

        public JsonResult GetAreaComboxTree()
        {
            var result = areaBll.GetAreaComboxTree();
            return Json(result);
        }
        #endregion

        #region 单据模板管理
        public ActionResult LKBillTemplateIndex()
        {
            var template = lKBillTemplateBll.GetLKBillTemplates();
            if (!template.Any()) return View(new LKBillTemplateDto());


            var tempdto = new LKBillTemplateDto();

            var zerocontracttemp = template.FirstOrDefault(t => t.BillType == 1);
            var contracttemp = template.FirstOrDefault(t => t.BillType == 2);
            if (zerocontracttemp != null)
            {
                tempdto.LKZeroWarehouseContract = JsonConvert.DeserializeObject<LKZeroWarehouseContract>(zerocontracttemp.TemplateContent);
            }
            if (contracttemp != null)
            {
                tempdto.LKWarehouseContract = JsonConvert.DeserializeObject<LKWarehouseContract>(contracttemp.TemplateContent);
            }
            return View(tempdto);
        }

        /// <summary>
        /// 保存零仓合同模板
        /// </summary>
        /// <param name="kZeroWarehouseContract"></param>
        /// <returns></returns>
        public JsonResult SaveLKZeroWarehouseContractTemplate(LKZeroWarehouseContract kZeroWarehouseContract)
        {
            LKBillTemplate lKBillTemplate = new LKBillTemplate
            {
                BillType = (int)BillTypeTemplate.ZeroWarehouse,
                TemplateContent = JsonConvert.SerializeObject(kZeroWarehouseContract)
            };
            var result = lKBillTemplateBll.SaveLKBillTemplate(lKBillTemplate);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        //保存包仓合同模板
        public JsonResult SaveLKWarehouseContractTemplate(LKWarehouseContract lKWarehouseContract)
        {
            LKBillTemplate lKBillTemplate = new LKBillTemplate
            {
                BillType = (int)BillTypeTemplate.Warehouse,
                TemplateContent = JsonConvert.SerializeObject(lKWarehouseContract)
            };
            var result = lKBillTemplateBll.SaveLKBillTemplate(lKBillTemplate);
            //string message = result ? "新增成功" : "新增失败";
            return Json(new { result.Success, result.Msg, Result = lKWarehouseContract });
        }

        //保存商品入库单模板
        public JsonResult SaveLKWarehouseEntryTemplate(LKWarehouseEntry lKWarehouseEntry)
        {
            LKBillTemplate lKBillTemplate = new LKBillTemplate
            {
                BillType = (int)BillTypeTemplate.WarehouseEntry,
                TemplateContent = JsonConvert.SerializeObject(lKWarehouseEntry)
            };
            var result = lKBillTemplateBll.SaveLKBillTemplate(lKBillTemplate);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }
        //保存商品出库单模板
        public JsonResult SaveLKWarehouseOutTemplate(LKWarehouseOut lKWarehouseOut)
        {
            LKBillTemplate lKBillTemplate = new LKBillTemplate
            {
                BillType = (int)BillTypeTemplate.WarehouseOut,
                TemplateContent = JsonConvert.SerializeObject(lKWarehouseOut)
            };
            var result = lKBillTemplateBll.SaveLKBillTemplate(lKBillTemplate);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        //保存商品调仓单模板
        public JsonResult SaveLKWarehouseAdjustTemplate(LKWarehouseAdjust lKWarehouseAdjust)
        {
            LKBillTemplate lKBillTemplate = new LKBillTemplate
            {
                BillType = (int)BillTypeTemplate.WarehouseAdjust,
                TemplateContent = JsonConvert.SerializeObject(lKWarehouseAdjust)
            };
            var result = lKBillTemplateBll.SaveLKBillTemplate(lKBillTemplate);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        //保存商品转卡单模板
        public JsonResult SaveLKTransferTemplate(LKTransfer lKTransfer)
        {
            LKBillTemplate lKBillTemplate = new LKBillTemplate
            {
                BillType = (int)BillTypeTemplate.WarehouseTransfer,
                TemplateContent = JsonConvert.SerializeObject(lKTransfer)
            };
            var result = lKBillTemplateBll.SaveLKBillTemplate(lKBillTemplate);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }


        /// <summary>
        /// 零包仓合同模板
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult _LKZeroWarehouseContractTemplate()
        {
            LKZeroWarehouseContract lKZeroWarehouseContract = new LKZeroWarehouseContract();
            var template = lKBillTemplateBll.GetLKBillTemplateByBillType(1);
            if (template != null)
            {
                lKZeroWarehouseContract = JsonConvert.DeserializeObject<LKZeroWarehouseContract>(template.TemplateContent);
            }
            return PartialView(lKZeroWarehouseContract);
        }

        /// <summary>
        /// 全包仓合同模板
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult _LKWarehouseContractTemplate()
        {
            LKWarehouseContract lKWarehouseContract = new LKWarehouseContract();
            var template = lKBillTemplateBll.GetLKBillTemplateByBillType(2);
            if (template != null)
            {
                lKWarehouseContract = JsonConvert.DeserializeObject<LKWarehouseContract>(template.TemplateContent);
            }
            return PartialView(lKWarehouseContract);
        }

        /// <summary>
        /// 商品入库单模板
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult _LKWarehouseEntryTemplate()
        {
            LKWarehouseEntry lKWarehouseEntry = new LKWarehouseEntry();
            var template = lKBillTemplateBll.GetLKBillTemplateByBillType(3);
            if (template != null)
            {
                lKWarehouseEntry = JsonConvert.DeserializeObject<LKWarehouseEntry>(template.TemplateContent);
            }
            return PartialView(lKWarehouseEntry);
        }

        //商品出库单模板
        [HttpPost]
        public ActionResult _LKWarehouseOutTemplate()
        {
            LKWarehouseOut lKWarehouseOut = new LKWarehouseOut();
            var template = lKBillTemplateBll.GetLKBillTemplateByBillType(4);
            if (template != null)
            {
                lKWarehouseOut = JsonConvert.DeserializeObject<LKWarehouseOut>(template.TemplateContent);
            }
            return PartialView(lKWarehouseOut);
        }
        /// <summary>
        /// 商品调仓单模板
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult _LKWarehouseAdjustTemplate()
        {
            LKWarehouseAdjust lKWarehouseAdjust = new LKWarehouseAdjust();
            var template = lKBillTemplateBll.GetLKBillTemplateByBillType(5);
            if (template != null)
            {
                lKWarehouseAdjust = JsonConvert.DeserializeObject<LKWarehouseAdjust>(template.TemplateContent);
            }
            return PartialView(lKWarehouseAdjust);
        }

        /// <summary>
        /// 商品转卡单模板
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult _LKTransferTemplate()
        {
            LKTransfer lKTransfer = new LKTransfer();
            var template = lKBillTemplateBll.GetLKBillTemplateByBillType(6);
            if (template != null)
            {
                lKTransfer = JsonConvert.DeserializeObject<LKTransfer>(template.TemplateContent);
            }
            return PartialView(lKTransfer);
        }
        #endregion

        #region 公司管理
        public ActionResult CompanyList()
        {
            return View();
        }

        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="customerInput"></param>
        /// <returns></returns>
        public JsonResult GetLKCompanyPageList(LKCompanyInput input)
        {
            var result = lKCompanyBll.GetLKCompanyPageList(input);
            return JsonList(result.Total, result.List.ToArray());
        }


        /// <summary>
        /// 获取公司表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetLKCompany()
        {
            var result = lKCompanyBll.GetLKCompanys();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 新增公司表
        /// </summary>
        /// <param name="lKCompany"></param>
        /// <returns></returns>
        public JsonResult AddLKCompany(LKCompany lKCompany)
        {
            var result = lKCompanyBll.AddLKCompany(lKCompany);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        /// <summary>
        /// 编辑公司表
        /// </summary>
        /// <param name="lKCompany"></param>
        /// <returns></returns>
        public JsonResult EditLKCompany(LKCompany lKCompany)
        {
            var result = lKCompanyBll.EditLKCompany(lKCompany);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除公司表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteLKCompany(int id)
        {
            var result = lKCompanyBll.DeleteLKCompany(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }
        #endregion

        #region 客户级别

        //
        // GET: /CustomerLevel/

        public ActionResult CustomerLevelList()
        {
            return View();
        }


        /// <summary>
        /// 获取客户等级
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCustomerLevel()
        {
            var result = customerlevelBll.GetLKCustomerLevels();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 新增客户等级
        /// </summary>
        /// <param name="customerLevel"></param>
        /// <returns></returns>
        public JsonResult AddCustomerLevel(LKCustomerLevel customerLevel)
        {
            var result = customerlevelBll.AddCustomerLevel(customerLevel);
            //string message = result ? "新增成功" : "新增失败";
            return Json(result.Success, result.Msg);
        }

        /// <summary>
        /// 编辑客户等级
        /// </summary>
        /// <param name="customerLevel"></param>
        /// <returns></returns>
        public JsonResult EditCustomerLevel(LKCustomerLevel customerLevel)
        {
            var result = customerlevelBll.EditCustomerLevel(customerLevel);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除客户等级
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteCustomerLevel(int id)
        {
            var result = customerlevelBll.DeleteCustomerLevel(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }

        #endregion
    }
}
